//dml/volumeDml.js
//与数据库交互
var mysql=require('mysql');
var $conf=require('../config/db');
var $util=require('../util/util');
var $sql=require('./volumeSql');

//连接池
var pool=mysql.createPool($util.extend({},$conf.mysql));

var jsonWrite=function(res,ret){
    if(typeof ret=='undefind'){
        res.json({
            code:'0',
            msg:'操作失败'
        });
    }else{
        res.json(ret);
    }
};
module.exports={
    register:function(req,res,next){
        pool.getConnection(function(err,con){
            var param=req.query;
            console.log(param);
            con.query($sql.register,[param.user,param.password,param.email,param.mobile,param.terms],function(err,result,fields){
                if (err) {
                    console.log(err);
                }
                else {
                    console.log(typeof result);
                    console.log(result);
                    var uId = result.insertId;
                    var data={
                        code:110,
                        msg:'注册成功!',
                        userId:uId
                    }
                jsonWrite(res,data);
                con.release();}
            })
        })
    },
    userLogin:function(req,res,next){
        pool.getConnection(function(err,con){
            var param=req.query;
            con.query($sql.userLogin,[param.name],function(err,result){
                jsonWrite(res,result);
                con.release();
            })
        })
    },

};